package com.suxin.security;

import com.suxin.security.builder.AbstractConfigureSecurityBuilder;
import com.suxin.security.builder.HttpSecurityBuilder;
import com.suxin.security.builder.SecurityBuilder;
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
import org.springframework.security.web.util.matcher.RequestMatcher;

import javax.servlet.Filter;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Tang
 * @classname HttpSecurity
 * @description [  ]
 * @date 2022/8/16 17:05
 */
public class HttpSecurity extends AbstractConfigureSecurityBuilder<DefaultSecurityFilterChain,HttpSecurity>
        implements SecurityBuilder<DefaultSecurityFilterChain>, HttpSecurityBuilder<HttpSecurity> {

    private final List<Filter> filters = new ArrayList<>();
    private final RequestMatcher requestMatcher = AnyRequestMatcher.INSTANCE;

    @Override
    public HttpSecurity addFilter(Filter filter) {
        filters.add(filter);
        return this;
    }

    @Override
    protected DefaultSecurityFilterChain preformBuild() {
        return new DefaultSecurityFilterChain(requestMatcher,filters);
    }
}
